package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车相关接口接口")
public class ShoppingCartController {
    @Autowired
    ShoppingCartService shoppingCartService;
    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 查看用户的购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result list (){
      return Result.success(shoppingCartService.getShoppingCart());
    }
    /**
     * 删除一个商品
     */
    @PostMapping("/sub")
    public Result delShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.delShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 清空购物车
     */
    @DeleteMapping("/clean")
    public Result deleteCart(){
        shoppingCartService.deleteCart();
        return Result.success();
    }
}
